<script>
	export default {
		onLaunch: function() {
			    var url = this.$ProjectConfig.API_BASE_URL + '/user/login';
				const _this=this;
			    uni.login({
			      success(res) {
			        if (res.code) {
			          //发起网络请求
			          wx.request({
			            url: url,
			            data: {
			              js_code: res.code
			            },
			            method: 'POST',
			            success(res) {
							console.log(res.data.code);
						  if(res.data.code==200){
							  _this.changeTabbar(res.data.identity);
							  //本地存储
							  try {
							    wx.setStorageSync('user_id', res.data.userid);
							  } catch (e) {}
							  wx.setStorageSync('status','bound')
							  _this.$isResolve();
						  }
						  else{
							  console.log("跳转到绑定界面");
							  try {
							  	wx.setStorageSync('auth_token', res.data.openid);
							  } catch (e) {}
							  wx.setStorageSync('status','unbound')
							  _this.$isResolve();
						  }
			              
			            },
			            fail(err) {
			              console.log("失败");
			            }
			          });
			        } else {
			          console.log('登录失败！' + res.errMsg);
			        }
			      }
			    });
				
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			changeTabbar(identity){
				if(identity=='t'){
					uni.setTabBarItem({
					  index: 0,
					  text: 'text',
					  iconPath: '/path/to/iconPath',
					  selectedIconPath: '/path/to/selectedIconPath'
					})
				}
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
